package dome3Set;

import java.util.Objects;

public class SetDome2Student {
    private String name;
    private int age;
    private String address;

    public SetDome2Student() {
    }

    public SetDome2Student(String address, int age, String name) {
        this.address = address;
        this.age = age;
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    //只要属性值相同，就认为是同一个对象

    //如果没有equals方法和hashCode方法，将无法实现集合去重
    @Override
    public boolean equals(Object o) {
        //1.如果直接比较地址，就认为两个对象是同一个对象
        if (this == o) return true;
        //2.判断是否为空，并且判断是否为同一个对象
        if (o == null || getClass() != o.getClass()) return false;
        //3.比较两个对象的属性值是否相同
        SetDome2Student that = (SetDome2Student) o;
        return age == that.age && Objects.equals(name, that.name) && Objects.equals(address, that.address);
    }

    @Override
    public int hashCode() {
        //包装了不同的对象，但是返回相同的hash值
        return Objects.hash(name, age, address);
    }

    @Override
    public String toString() {
        return "SetDome2Student{" +
                "address='" + address + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}'+"\n";
    }
}
